﻿using System;

namespace Sunny.FrameDecoder.Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            int a = 34;
            int b = 2;
            a = BitHelper.SetFlag(a, b, true);
            Console.WriteLine(a);
            Console.WriteLine(BitHelper.HasFlag(a, b));
            a = BitHelper.SetFlag(a, b, false);
            Console.WriteLine(a);
            Console.WriteLine(BitHelper.HasFlag(a, b));

            //int intvalue = RandomEx.Next(int.MaxValue);
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(intvalue), ByteHelper.GetBytesFromInt(intvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(intvalue).Reversed(), ByteHelper.GetBytesFromInt(intvalue, false));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-intvalue), ByteHelper.GetBytesFromInt(-intvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-intvalue).Reversed(), ByteHelper.GetBytesFromInt(-intvalue, false));
            //
            //uint uintvalue = (uint)(uint.MaxValue - RandomEx.Next(short.MaxValue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(uintvalue), ByteHelper.GetBytesFromUInt(uintvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(uintvalue).Reversed(), ByteHelper.GetBytesFromUInt(uintvalue, false));
            //
            //double doublevalue = intvalue * 0.1234;
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(doublevalue), ByteHelper.GetBytesFromDouble(doublevalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(doublevalue).Reversed(), ByteHelper.GetBytesFromDouble(doublevalue, false));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-doublevalue), ByteHelper.GetBytesFromDouble(-doublevalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-doublevalue).Reversed(), ByteHelper.GetBytesFromDouble(-doublevalue, false));
            //
            //float floatvalue = intvalue * 0.2234f;
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(floatvalue), ByteHelper.GetBytesFromFloat(floatvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(floatvalue).Reversed(), ByteHelper.GetBytesFromFloat(floatvalue, false));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-floatvalue), ByteHelper.GetBytesFromFloat(-floatvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(-floatvalue).Reversed(), ByteHelper.GetBytesFromFloat(-floatvalue, false));
            //
            //short shortvalue = (short)RandomEx.Next(short.MaxValue);
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(shortvalue), ByteHelper.GetBytesFromShort(shortvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(shortvalue).Reversed(), ByteHelper.GetBytesFromShort(shortvalue, false));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes((short)-shortvalue), ByteHelper.GetBytesFromShort((short)-shortvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes((short)-shortvalue).Reversed(), ByteHelper.GetBytesFromShort((short)-shortvalue, false));
            //
            //ushort ushortvalue = (ushort)(ushort.MaxValue - RandomEx.Next(byte.MaxValue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(ushortvalue), ByteHelper.GetBytesFromUShort(ushortvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(ushortvalue).Reversed(), ByteHelper.GetBytesFromUShort(ushortvalue, false));
            //
            //long longvalue = RandomEx.Next(int.MaxValue) * RandomEx.Next(int.MaxValue);
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(longvalue), ByteHelper.GetBytesFromLong(longvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(longvalue).Reversed(), ByteHelper.GetBytesFromLong(longvalue, false));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes((long)-longvalue), ByteHelper.GetBytesFromLong((long)-longvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes((long)-longvalue).Reversed(), ByteHelper.GetBytesFromLong((long)-longvalue, false));
            //
            //ulong ulongvalue = (ulong)(RandomEx.Next(int.MaxValue) * RandomEx.Next(int.MaxValue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(ulongvalue), ByteHelper.GetBytesFromULong(ulongvalue));
            //ThrowHelper.ThrowIfNotEquel(BitConverter.GetBytes(ulongvalue).Reversed(), ByteHelper.GetBytesFromULong(ulongvalue, false));


            TestByteFrameDecoder.TestFixedLengthFrameDecoder();
            TestByteFrameDecoder.TestDelimiterBasedFrameDecoder();
            TestByteFrameDecoder.TestHeaderDelimiterFrameDecoder();
            TestByteFrameDecoder.TestHeaderTailFrameDecoder();
            TestByteFrameDecoder.TestLengthValueFrameDecoder();
            TestByteFrameDecoder.TestTagLengthValueFrameDecoder();
            TestByteFrameDecoder.TestHeaderTagLengthValueTailFrameDecoder();

            TestStringFrameDecoder.TestNMEA0183FrameDecoder();
            TestStringFrameDecoder.TestLineBasedFrameDecoder();

            TestByteFrameDecoder.TestCreateFrame();
        }


    }
}